﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Chefbook.ViewModels;
using Chefbook.DataAccess;
using UnitTests.Properties;

namespace UnitTests.ViewModelsTests
{
    [TestFixture]
    public class MainFormViewModelFixture
    {
        MainFormViewModel mainVM;
        ChefbookXmlRepository repo;

        [SetUp]
        public void Init()
        {
            
            repo = new ChefbookXmlRepository(Resources.RecipeXmlPath, Resources.CategoryXmlPath);
            mainVM = new MainFormViewModel(repo);
            Assert.AreEqual(mainVM.Categories.SelectedCategory, mainVM.RecipeList.CurrentCategory);
            Assert.AreEqual(mainVM.RecipeList.SelectedRecipe, mainVM.PreviewedRecipe);
        }

        [Test]
        public void SelectingCategoryDisplaysCategorysRecipes()
        {
            var category = repo.RootCategories[0].Subcategories[0].Subcategories[3];
            mainVM.Categories.AssertPropertyChangedFired(()=>
                mainVM.Categories.SelectedCategory = category, "SelectedCategory");
            Assert.AreEqual(category, mainVM.RecipeList.CurrentCategory);
        }

        [Test]
        public void SelectingRecipeDisplaysRecipeDetails()
        {
            var recipe = repo.Recipes.Values.ToList()[3];
            mainVM.AssertPropertyChangedFired(()=>
                mainVM.RecipeList.SelectedRecipe = recipe, "PreviewedRecipe");
            Assert.AreEqual(recipe, mainVM.PreviewedRecipe);
        }
    }
}
